package C;

import java.util.Scanner;

public class C55 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] target = sc.nextLine().split("");
        String[] source = sc.nextLine().split("");
        System.out.println(getResult(target,source));
    }

    public static int getResult(String[] target,String[] source) {
        int pTarget = target.length-1;
        int pSource = source.length-1;

        while(pSource>=0) {
            if (target[pTarget].equals(source[pSource])) {
                pTarget--;
            }
            if (pTarget<0) {
                return pSource;
            }
            pSource--;
        }
        return -1;

    }
}
